
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="sj" tagdir="/WEB-INF/tags/spring-jquery-tags"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<link href="<c:url value='/css/dhtmlxcombo.css' />" rel="stylesheet" type="text/css"/>
<script type="text/javascript">
	$(document).ready(function() {
		$("#editPartnerForm").validate({
			rules : {
				email : {
					email : true
				},
					partnerName : {
						required : true
				}, 
				url : {
					isValidUrl : true
				}
			}
		});
		
		<c:choose>
			<c:when test="${partner.id !=null and partner.id gt 0}">			
				$('#pageTitle').text('<spring:message code="editPartner.heading.view" />');
			</c:when>
			<c:otherwise>
				$('#pageTitle').text('<spring:message code="editPartner.heading" />');	
			</c:otherwise>
		</c:choose>	
		
		
// 		$("#countries").change(function() {
// 			loadDataViaAjax("loadStates.do", {
// 				"countryId" : this.value
// 			}, parseStatesJson);
// 		});
		
// 		$("#countries").change();
		
		$("#editPartnerForm").validate({
			rules : {
				name : {
					required : true
				}
			}
		});
	});
	
	function parseStatesJson(data) {
// 		var stateId = '${donor.state.id}';
		
// 		var html = '<option value="">Select</option>';
// 		if (data) {
// 			for (p in data) {
// 				if(stateId == p) {
// 					html += "<option selected='selected' value='" + p + "'>" + data[p] + "</option>";
// 				} else {
// 					html += "<option value='" + p + "'>" + data[p] + "</option>";
// 				}
// 			}
// 		}
// 		$("#states option").remove();
// 		$("#states").append(html);
		  z2.clearAll();
		  if (data) {
		   for (p in data) {
		    z2.addOption([[p,data[p]]]);
		   }
		  }
	}
	
	$('.close-button').click(function() {
		if(confirm('Are you sure that you want to close the form without saving the record?')) {
			window.location = '../secure/showDashboard.do';
		}	
	});
	$('#cancelButton').click(function() {
		var ans = confirm('Are you sure you want to cancel editing this record without saving it?');
		if (ans) {
			loadDiv('content', 'showAddPartnergrant.do');
		}
	});
	
	$.validator.addMethod("isValidUrl", function(value, element) {
		if(jQuery.trim(value).length == 0){
			return true;
		}
		 var urlRegExp= /^(((ht|f){1}(tp:[/][/]){1})|((www.){1}))[-a-zA-Z0-9@:%_\+.~#?&//=]+$/
		return (urlRegExp.test(value));
	}, "Please enter valid URL");
		
	var z1 = dhtmlXComboFromSelect("countries",274);
		z1.enableFilteringMode(true);
		z1.attachEvent("onChange", function(){ 
		  loadDataViaAjax("loadStates.do", {
		   "countryId" : z1.getSelectedValue()
		  }, parseStatesJson);
	 });
	 
	var z2 = dhtmlXComboFromSelect("states",274);
	z2.enableFilteringMode(true);
	
	var z3 = dhtmlXComboFromSelect("orgType",274);
	z3.enableFilteringMode(true);
	
	var z4 = dhtmlXComboFromSelect("status",274);
	z4.enableFilteringMode(true);
</script>
<div id="editPartnerDiv">
	<form:form name="editPartnerForm" id="editPartnerForm" action="savePartner.do" method="post" modelAttribute="partner">
		<form:hidden path="id" />
        <input type="hidden" name="prevUrl" value="${prevUrl }" />
		<c:choose>
			<c:when test="${partner.fromProject=='true'}">
				<input type="hidden" name="fromProject" value="true" />
			</c:when>
			<c:otherwise>
				<input type="hidden" name="fromProject" value="false" />
			</c:otherwise>
		</c:choose>
		<div class="main_form">
	    	<div class="form_head">
	    		<a href="#" class="close-button gray_btn floatR">Close Form</a>
	    		<br class="clear" />
	    	</div>
	        <div class="form_cont">
		<table width="100%" border="0">
			<%-- <tr class="row">
				<td class="menu-heading" colspan="3"><spring:message code="editPartner.heading" /></td>
			</tr> --%>
			<tr class="row">
				<td class="input-field" colspan="2"><%@ include file="/common/messages.jsp"%></td>
			</tr>
			<tr>
				<td style="vertical-align: top;"><table>
						<tr class="row">
							<td class="label"><spring:message code="editPartner.label.id" /></td>
							<td class="input-field"><form:input path="id" cssClass="text_grey uneditable" disabled="true" /></td>
							<td><form:errors path="id" cssClass="error" /></td>
						</tr>
						<tr class="row">
							<td class="label"><spring:message code="editPartner.label.name" /></td>
							<td class="input-field"><form:input path="partnerName" cssClass="text_blue input-required" /></td>
							<td><form:errors path="partnerName" cssClass="error" /></td>
						</tr>
						<tr class="row">
							<td class="label"><spring:message code="editPartner.label.Type" /></td>
							<td class="input-field"><form:select id="orgType" path="type" cssClass="text_white">
									<form:option value="Cipe Partner" label="Cipe Partner" />
									<form:option value="Other" label="Other" />
								</form:select></td>
							<td><form:errors path="type" cssClass="error" /></td>
						</tr>
						<tr class="row">
							<td class="label"><spring:message code="editPartner.label.Status" /></td>
							<td class="input-field"><form:select id="status" path="status" cssClass="text_white">
									<form:option value="Active" label="Active" />
									<form:option value="Inactive" label="Inactive" />
									<form:option value="Other" label="Other" />
								</form:select></td>
							<td><form:errors path="status" cssClass="error" /></td>
						</tr>
						<tr class="row">
							<td class="label"><spring:message code="editPartner.label.address1" /></td>
							<td class="input-field"><form:input path="address1" cssClass="text_white" /></td>
							<td><form:errors path="address1" cssClass="error" /></td>
						</tr>
						<tr class="row">
							<td class="label"><spring:message code="editPartner.label.address2" /></td>
							<td class="input-field"><form:input path="address2" cssClass="text_white" /></td>
							<td><form:errors path="address2" cssClass="error" /></td>
						</tr>
						<tr class="row">
							<td class="label"><spring:message code="editPartner.label.city" /></td>
							<td class="input-field"><form:input path="city" cssClass="text_white" /></td>
							<td><form:errors path="city" cssClass="error" /></td>
						</tr>
						<tr class="row">
							<td class="label"><spring:message code="editPartner.label.zipCode" /></td>
							<td class="input-field"><form:input path="zipCode" cssClass="text_white" /></td>
							<td><form:errors path="zipCode" cssClass="error" /></td>
						</tr>
						<tr class="row">
							<td class="label"><spring:message code="editPartner.label.country" /></td>
							<td class="input-field"><form:select path="country.id" id="countries" cssClass="text_white">
									<form:option value="" label="" />
									<form:options items="${countryList}" itemValue="id" itemLabel="displayName" />
								</form:select></td>
							<td><form:errors path="country.id" cssClass="error" /></td>
						</tr>
						<tr>
							<td class="label"><spring:message code="editPartner.label.state" /></td>
							<td class="input-field"><form:select path="state.id" id="states" cssClass="text_white">
								</form:select> <form:errors path="state.id" cssClass="error" /></td>
						</tr>
						<tr class="row">
							<td class="label"><spring:message code="editPartner.label.phone" /></td>
							<td class="input-field"><form:input path="phone" cssClass="text_white" /></td>
							<td><form:errors path="phone" cssClass="error" /></td>
						</tr>
						<tr class="row">
							<td class="label"><spring:message code="editPartner.label.fax" /></td>
							<td class="input-field"><form:input path="fax" cssClass="text_white" /></td>
							<td><form:errors path="fax" cssClass="error" /></td>
						</tr>
					</table></td>
				<td><table>
						<tr class="row">
							<td class="label"><spring:message code="editPartner.label.email" /></td>
							<td class="input-field"><form:input path="email" cssClass="text_white" /></td>
							<td><form:errors path="email" cssClass="error" /></td>
						</tr>
						<tr class="row">
							<td class="label"><spring:message code="editPartner.label.url" /></td>
							<td class="input-field"><form:input path="url" cssClass="text_white" /></td>
							<td><form:errors path="url" cssClass="error" /></td>
						</tr>
						<tr class="row">
							<td class="label"><spring:message code="editPartner.label.ContactFirstName" /></td>
							<td class="input-field"><form:input path="contactFirstName" cssClass="text_white" /></td>
							<td><form:errors path="contactFirstName" cssClass="error" /></td>
						</tr>
						<tr class="row">
							<td class="label"><spring:message code="editPartner.label.ContactMiddleName" /></td>
							<td class="input-field"><form:input path="contactMiddleName" cssClass="text_white" /></td>
							<td><form:errors path="contactMiddleName" cssClass="error" /></td>
						</tr>
						<tr class="row">
							<td class="label"><spring:message code="editPartner.label.ContactLastName" /></td>
							<td class="input-field"><form:input path="contactLastName" cssClass="text_white" /></td>
							<td><form:errors path="contactLastName" cssClass="error" /></td>
						</tr>
						<tr class="row">
							<td class="label"><spring:message code="editPartner.label.ContactPhone" /></td>
							<td class="input-field"><form:input path="contactPhone" cssClass="text_white" /></td>
							<td><form:errors path="contactPhone" cssClass="error" /></td>
						</tr>
						<tr class="row">
							<td class="label"><spring:message code="editPartner.label.ContactFax" /></td>
							<td class="input-field"><form:input path="contactFax" cssClass="text_white" /></td>
							<td><form:errors path="contactFax" cssClass="error" /></td>
						</tr>
						<tr class="row">
							<td class="label"><spring:message code="editPartner.label.ContactEmail" /></td>
							<td class="input-field"><form:input path="contactEmail" cssClass="text_white" /></td>
							<td><form:errors path="contactEmail" cssClass="error" /></td>
						</tr>
						<tr class="row">
							<td class="label"><spring:message code="editPartner.label.lastUpdated" /></td>
							<td class="input-field"><form:input path="updationDate" cssClass="text_grey uneditable" disabled="true" /></td>
							<td><form:errors path="updationDate" cssClass="error" /></td>
						</tr>
						<tr class="row">
							<td class="label"><spring:message code="editPartner.label.lastUpdatedBy" /></td>
							<td class="input-field"><form:input path="updatedBy.fullName" cssClass="text_grey uneditable" disabled="true" /></td>
							<td><form:errors path="updatedBy" cssClass="error" /></td>
						</tr>
						<tr class="row">
							<td class="label"><spring:message code="editPartner.label.createDate" /></td>
							<td class="input-field"><form:input path="creationDate" cssClass="text_grey uneditable" disabled="true" /></td>
							<td><form:errors path="creationDate" cssClass="error" /></td>
						</tr>
						<tr class="row">
							<td class="label"><spring:message code="editPartner.label.createdBy" /></td>
							<td class="input-field"><form:input path="createdBy.fullName" cssClass="text_grey uneditable" disabled="true" /></td>
							<td><form:errors path="createdBy" cssClass="error" /></td>
						</tr>
					</table></td>
			</tr>
			<tr class="row">
				<td colspan="5" class="input-field" align="center"><input id="cancelButton" type="button" value="Cancel" class="blue_btn" tabindex="-1"/><sj:submit id="loginFormSubmit" target="editPartnerDiv" key="editPartner.button.save" validate="true" cssClass="blue_btn"/></td>
			</tr>
		</table>
		</div>
		</div>
	</form:form>
</div>
